package com.sgb.kjwl.viewmodel.machine;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.model.entity.MachineInEntity;
import com.sgb.link.entity.PublicTypeEntity;
import com.sgb.kjwl.model.entity.ParentAreaEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.fragment.machine.MachineCompanyFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MLog;

import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;

@Deprecated
public class MachineCompanyFragModel extends BaseViewModel {
    private HomeRepertory repertory;
    private MachineCompanyFragment fragment;

    public MachineCompanyFragModel(MachineCompanyFragment fragment, HomeRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
    }

    public void getMachineAreaModel() {
        repertory.getMachineArea(650000)
                .subscribe(new Consumer<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>() {
                    @Override
                    public void accept(BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>> listBaseEntity) throws Exception {
                        fragment.showAreaPop(listBaseEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        MLog.d(AppConstant.API_LOG, throwable.getMessage());
                    }
                });
    }

    public void getMachineTypeModel() {
        repertory.getMachineType()
                .subscribe(new Consumer<BaseEntity<List<PublicTypeEntity>>>() {
                    @Override
                    public void accept(BaseEntity<List<PublicTypeEntity>> listBaseEntity) throws Exception {
                        fragment.showTypePop(listBaseEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        MLog.d(AppConstant.API_LOG, throwable.getMessage());
                    }
                });
    }

    public void getMachineInModel(int sort,Map map) {
        map.put("categoryNo", "");
        map.put("typeNo", "");
        repertory.getMachineIn(1, 10, sort ,map)
                .subscribe(new Consumer<BaseEntity<ListResponse<List<MachineInEntity>>>>() {
                    @Override
                    public void accept(BaseEntity<ListResponse<List<MachineInEntity>>> listResponseBaseEntity) throws Exception {
                        fragment.showInView(listResponseBaseEntity.getData().getList());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        MLog.d(AppConstant.API_LOG, throwable.getMessage());
                    }
                });
    }

}
